package cc.bluemc.modules.generateCode.service;

import cc.bluemc.platform.springUtil.SpringConfigUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;


public class GenerateServiceFactory {
	
	@Autowired
	private static JdbcTemplate jdbcTemplate;
	
	
	public static IGenerateService createGenerateService() {
		try {
			String poductName=getPoductName();
			IGenerateService service= (IGenerateService) SpringConfigUtil.getBean("GenerateServiceImpl_" + poductName);
			return service;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static IGenerateTableService createGenerateTableService() {
		try {
			String poductName=getPoductName();
			IGenerateTableService service= (IGenerateTableService) SpringConfigUtil.getBean("GenerateTableServiceImpl_"+poductName);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	private static String getPoductName() throws SQLException{
		DatabaseMetaData md = jdbcTemplate.getDataSource().getConnection().getMetaData();
		String poductName= md.getDatabaseProductName();
		return poductName;
	}

}
